# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Eric Timmons <etimmons@alum.mit.edu>
# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=sbcl
pkgver=2.2.6
pkgrel=0
pkgdesc="Steel Bank Common Lisp"
url="http://www.sbcl.org/"
# riscv64: No rule to make target 'genesis/Makefile.features'.  Stop.
arch="all !s390x !riscv64"
license="custom"
options="!check"
checkdepends="ed"
makedepends="
	ecl-dev>=21.2.1-r2
	gmp-dev
	gc-dev
	libffi-dev
	linux-headers
	zstd-dev
	emacs-nox
	mpfr-dev
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.bz2::https://prdownloads.sourceforge.net/sbcl/sbcl-$pkgver-source.tar.bz2
	ppc-musl.patch
	march-armv5-removed.patch
	"

build() {
	#All systems can build with these features enabled
	all_arch_conf='--with-sb-test --with-sb-unicode --with-sb-core-compression --with-sb-linkable-runtime --with-sb-dynamic-core'

	#Please add additional package support by arch
	#armv7 is incapable of supporting sb:thread
	#x86 can be built with sb:thread, but as of 2.2.5 it causes a memory corruption
	case "$CARCH" in
		armv7) conf="$all_arch_conf" ;;
		x86) conf="$all_arch_conf --without-sb-thread" ;;
		x86_64) conf="$all_arch_conf --fancy --with-sb-thread" ;;
		aarch64) conf="$all_arch_conf --fancy --with-sb-thread" ;;
		riscv64) conf="$all_arch_conf --fancy --with-sb-thread" ;;
		ppc64le) conf="$all_arch_conf" ;;
	esac

	GNUMAKE=make ./make.sh ecl --prefix=/usr $conf
}

package() {
	INSTALL_ROOT="$pkgdir/usr" \
		LIB_DIR="/usr/lib" \
		DOC_DIR="$pkgdir/usr/share/doc/$pkgname" \
		sh install.sh

	install -Dm644 COPYING \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE.txt

	rmdir "$pkgdir"/usr/share/doc/$pkgname/html \
		"$pkgdir"/usr/share/info 2>/dev/null || true
}

sha512sums="
d8460cfb0044b02b3989ff2266355c067035eab5cde2afb8d170870e4bf54112ec878e7d5f809adaaabcfef3df1cd9ef2d94517b772ba376ca53b9ee78893baf  sbcl-2.2.6.tar.bz2
549cc9936ddbd4c19067a455dfad151bd0ce59200b2dce761de67e259e621e4174beefaa5a322886bcd731d2470d229a3e1b75a55a194c54e2feb7c0bcdffb37  ppc-musl.patch
253ad5d87cd7c656f1d011ec3519950f4dbffc9fb9a4a8e12f61c7cc51915ec4f3bf2fc47024613eeb5741851f07047ad3f4237b74ecc2d8bb93cc0059de6092  march-armv5-removed.patch
"
